package com.paping
{
	
	[SWF(width="1280", height="720", frameRate="30", backgroundColor="#000000")]
	public class StarlingFullScreen
	{
		public var mStarling:Starling;
		public function StarlingFullScreen()
		{
			var stageWidth:int  = 1280;
			var stageHeight:int = 720;
			
			mStarling = new Starling(Game, stage, viewPort);
			mStarling.addEventListener(Event.CONTEXT3D_CREATE, onContext3dCreateHandler);
			/*
			
			*/
			
			mStarling.addEventListener(Event.ROOT_CREATED, function onStart(e:Event, game:SqueezGame):void
			{
				e.currentTarget.removeEventListener(Event.ROOT_CREATED, onStart);
				var game:SqueezGame = mStarling.root as Game;
				
				var mWidthRate:Number = stage.stageWidth / stageWidth;
				var mHeightRate:Number = stage.stageHeight / stageHeight;
				var mRealWidth:Number = 0;
				var mRealHeight:Number = 0;
				
				
				if(mWidthRate < mHeightRate){
					mRealWidth = stage.stageWidth;
					mRealHeight = (stageHeight * stage.stageWidth) / stageWidth;
				}else if(mWidthRate > mHeightRate){
					mRealWidth = (stageWidth * stage.stageHeight) / stageHeight;
					mRealHeight = stage.stageHeight;
				}else{
					mRealWidth = stage.stageWidth;
					mRealHeight = stage.stageHeight;
				}
				
				
				mStarling.root.scaleX = mRealWidth / stage.stageWidth;
				mStarling.root.scaleY = mRealHeight / stage.stageHeight;
				
				mStarling.root.x = (stage.stageWidth - mRealWidth ) / 2 * (stageWidth / stage.stageWidth);
				mStarling.root.y = (stage.stageHeight - mRealHeight ) / 2 * (stageHeight / stage.stageHeight);
				
				
				GameData.getInstance().X_START_POSITION = -(stage.stageWidth - mRealWidth ) / 2;
				GameData.getInstance().X_END_POSITION = stageWidth + (stage.stageWidth - mRealWidth ) / 2;
				GameData.getInstance().Y_START_POSITION = -(stage.stageHeight - mRealHeight ) / 2;
				GameData.getInstance().Y_END_POSITION = stageHeight + (stage.stageHeight - mRealHeight ) / 2;
				
				//game.start(assets);
				mStarling.start();
				
			}
		}
		
		private function onContext3dCreateHandler(e:Object):void
		{
			e.currentTarget.removeEventListener(Event.CONTEXT3D_CREATE, onContext3dCreateHandler);
			var view = new Rectangle();
			view.width = stage.stageWidth;
			view.height = stage.stageHeight;
			
			mStarling.viewPort = view;
			
		}
	}

}